import 'package:flutter/material.dart';
import 'package:idraw/extra_02_svg/svg_parser/svg_utils.dart';

import '../svg_parser/svg_parser.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: CustomPaint(
            size: Size(128, 128),
            painter: SVGTestPainter(),
          ),
        ),
      ),
    );
  }
}

class SVGTestPainter extends CustomPainter {
  final SVGParser svgParser = SVGParser();

  Paint mainPaint = Paint();

  @override
  void paint(Canvas canvas, Size size) {


//     String src = """
// <svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
//     <path d="M0,0 H128 V128 H0" fill="#FFFFFF" />
//
//     <path d="M30,50 a30 40 0 1 1 50 80" stroke="#7E4FFF" stroke-width="2"/>
//
//     <path d="M50,50 l30 40 h-20 v30 h-10 L10 60" stroke="#7E4FFF" stroke-width="2"/>
// </svg>
// """;

    String src = """<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg t="1648260431391" class="icon" viewBox="0 0 1024 1024" version="1.1"
    xmlns="http://www.w3.org/2000/svg" p-id="2335" width="128" height="128">
    <defs>
        <style type="text/css">@font-face { font-family: feedback-iconfont; src:
            url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff2?t=1630033759944") format("woff2"),
            url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff?t=1630033759944") format("woff"),
            url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.ttf?t=1630033759944") format("truetype");
            }
        </style>
    </defs>
<path
    d="M849.698334 924.325662a156.070471 156.070471 0 0 0-139.202593-136.306089l-77.524088-8.007982a27.4316 27.4316 0 0 1-24.023948-22.14974l-10.222956-42.254887h2.044591a148.914402 148.914402 0 0 0 148.914402-154.877793l-2.214974-52.818609a87.576662 87.576662 0 0 0 40.210296-157.94468l17.038261-112.793288 28.453896-28.113131a17.038261 17.038261 0 0 0 5.111478-11.415635c0-3.23727 2.214974-78.376001-80.079827-132.728053-65.597305-43.277183-147.892106-36.291496-170.38261-34.076523-25.216626-11.586018-137.328384-56.567027-255.573916-7.8376a272.612177 272.612177 0 0 0-154.366645 175.834854 17.038261 17.038261 0 0 0 5.111478 17.038261l37.82494 34.076523 12.608313 101.036888a87.406279 87.406279 0 0 0 41.743739 156.581619l-2.214973 52.818609A148.914402 148.914402 0 0 0 423.23066 715.606964h2.044591l-10.222956 43.447566a27.261218 27.261218 0 0 1-23.853566 21.638591l-77.524088 8.007983a156.070471 156.070471 0 0 0-139.202592 136.306088l-10.222957 78.716766a17.038261 17.038261 0 0 0 14.652905 18.571705h2.214973a17.038261 17.038261 0 0 0 17.038262-14.823287l10.222956-78.716766a122.164332 122.164332 0 0 1 108.874488-106.148367l19.423618-2.044591A346.047082 346.047082 0 0 0 512 865.543661c11.926783 0 23.853565 0 35.439583-1.533443a8.519131 8.519131 0 0 0 7.667217-9.200661 8.689513 8.689513 0 0 0-9.200661-7.667218c-11.07487 1.022296-22.490505 1.533443-34.076522 1.533444A341.617134 341.617134 0 0 1 366.663633 817.83653l28.113131-2.896504A60.996975 60.996975 0 0 0 448.276904 766.721747l11.926782-51.114783H563.114783l11.926783 51.114783a61.167357 61.167357 0 0 0 53.840905 48.559044l27.772365 2.896504a284.368577 284.368577 0 0 1-27.601983 11.586018 8.519131 8.519131 0 0 0 2.896505 17.038261 8.519131 8.519131 0 0 0 2.896504 0 287.605846 287.605846 0 0 0 52.307462-24.535096l19.423617 2.044591a122.164332 122.164332 0 0 1 108.874488 106.148367l10.222957 78.716766a17.038261 17.038261 0 0 0 17.038261 14.823287h2.214974a17.038261 17.038261 0 0 0 14.652904-19.082853z m-103.76301-450.32124l-2.555739-59.804296 15.6752 8.519131a8.519131 8.519131 0 0 0 8.178365-14.99367l-24.535095-13.460226-1.192679-26.75007a53.840905 53.840905 0 0 1 4.429948 106.489131z m-511.147831-52.988992a53.840905 53.840905 0 0 1 48.388661-53.500139l-1.192678 26.75007-25.557392 13.460226a8.519131 8.519131 0 1 0 8.178366 14.99367l15.6752-8.519131-2.555739 59.804296a54.011288 54.011288 0 0 1-43.617949-52.988992z m52.137079-140.565653l-2.214974 52.818609a87.576662 87.576662 0 0 0-17.038261 2.385357l-11.926783-95.92541a17.038261 17.038261 0 0 0-5.452244-10.563722l-34.076522-31.009635a240.921011 240.921011 0 0 1 131.364993-142.95101c105.807601-43.788331 209.911376 0 228.312698 7.667217l-4.259565 20.105148a8.519131 8.519131 0 0 0 6.985687 9.711809H580.153044a8.519131 8.519131 0 0 0 8.178365-7.496835l3.23727-20.27553c15.6752-2.044591 90.813931-9.711809 147.892106 27.942748a132.898436 132.898436 0 0 1 64.575009 96.777322l-27.090835 26.75007a17.038261 17.038261 0 0 0-4.941095 9.541426l-17.038261 108.874489a88.08781 88.08781 0 0 0-15.164053-1.874209l-2.214974-52.818609a17.038261 17.038261 0 0 0-18.230939-17.038261 265.967255 265.967255 0 0 1-82.465184-12.267548 210.763289 210.763289 0 0 1-70.027252-31.350401l14.993669-92.517757a8.519131 8.519131 0 1 0-17.038261-2.726122l-14.993669 92.68814h-2.214974a406.532909 406.532909 0 0 1-110.067167 32.883844 661.766059 661.766059 0 0 1-133.579966 12.608313 17.038261 17.038261 0 0 0-17.890174 18.060557z m54.352052 365.811464A113.985966 113.985966 0 0 1 308.392781 562.262615l11.074869-263.752281a745.253538 745.253538 0 0 0 124.379306-13.289844 504.843675 504.843675 0 0 0 110.578314-31.861548 278.916333 278.916333 0 0 0 73.264523 31.520783 336.846421 336.846421 0 0 0 77.012939 13.460226L715.607219 562.262615a115.008262 115.008262 0 0 1-114.837879 119.267827H423.23066a113.985966 113.985966 0 0 1-82.805949-35.269201z"
    fill="#4C4497" p-id="2343"></path>
</svg>
""";
    canvas.scale(0.3,0.3);
    canvas.translate(-350, -500);
    List<SVGPathResult?> parserResults = svgParser.parser(src);
    parserResults.forEach((SVGPathResult? result) {
      if (result == null) return;
      if (result.path != null) {
        Path path = SvgUtils.convertFromSvgPath(result.path!);
        result.setPaint(mainPaint);
        canvas.drawPath(path, mainPaint);
      }
    });
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}
